package com.cloudweb.oa.controller;

import cn.js.fan.util.ErrMsgException;
import com.cloudweb.oa.api.ILicenseUtil;
import com.cloudweb.oa.service.LeaveBalanceService;
import com.cloudweb.oa.utils.LicenseConstUtil;
import com.cloudweb.oa.vo.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "人事模块")
@RestController
public class HrController {

    @Autowired
    LeaveBalanceService leaveBalanceService;

    @Autowired
    ILicenseUtil licenseUtil;

    @ApiOperation(value = "根据规则分发假期余额", notes = "根据规则分发假期余额", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long"),
    })
    @ApiResponses({ @ApiResponse(code = 200, message = "操作成功") })
    @ResponseBody
    @RequestMapping(value = "/hr/distributeLeaveBalanceByRuleId", method = RequestMethod.POST, produces = {"text/html;charset=UTF-8;", "application/json;"})
    public Result<Object> distributeLeaveBalanceByRuleId(Long id) {
        if (!licenseUtil.isEnabled(LicenseConstUtil.HR_HOLIDAY)) {
            return new Result<>(licenseUtil.getCompErrMsg(LicenseConstUtil.HR_HOLIDAY));
        }

        leaveBalanceService.distributeLeaveBalanceByRuleId(id, false);
        return new Result<>(true);
    }
}
